{include file=header.html}
<script type="text/javascript" language="javascript" src="{lib file=jquery-1.6.3.min.js}"></script>
<script language="javascript" type="text/javascript" src="{lib file=jquery.ui/jquery.ui.js}"></script>

<script language="javascript" type="text/javascript" src="{lib file=jquery.ui/chosen.jquery.js}"></script>

<link type="text/css" rel="stylesheet"  href="{lib file=jquery.ui/themes/chosen/chosen.css}">
<script language="javascript" type="text/javascript" src="{lib file=jquery.plugins/jquery.validate.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/common.js}"></script>
<script language="javascript" type="text/javascript" src="{lib file=ajaxfileupload.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/jquery.funkyUI.js}"></script>
<script type="text/javascript">
$(function(){
     $('#user_form').validate({
        onkeyup : false,
		onfocusout : false,
        rules : {
			user_name: {
				required: true,
				remote: 'index.php?app=member&act=check_user&user_name=' + $('#user_name').val() + '{if $smarty.get.act eq \'edit\'}&uid={$smarty.get.uid}{/if}'
			},
			factory_id:
			{
				required: true
			},
			password: {
				required: {if $smarty.get.act eq 'edit'}false{else}true{/if},
				rangelength: [6, 20]
			},
			password2: {
				required: function() {
					return $('#password').val() != '';
				},
				equalTo: '#password'
			},
			role: {
				required: true
			},
			email:{
				email:true
			}
		},
        messages : {
			user_name: {
				required: '{$lang.user_name_not_empty}',
				remote: '{$lang.user_name_is_exist}'
			},
			factory_id:
			{
				required: '请选择工厂'
			},
			password: {
				required: '{$lang.password_not_empty}',
				rangelength: '{$lang.password_length_error}'
			},
			password2: {
				required: '{$lang.confirm_password_not_empty}',
				equalTo: '{$lang.password_not_eq_confirm}'
			},
			role: {
				required: '{$lang.role_select_pls}'
			},
			email:{
				email:'{$lang.email_require}'
			}
		}
	 });
	/*  $('#role').change(function() {
	 	if ($(this).val() == $('#role option:last-child').val()) {
			$(this).parents('tr').next().show();
		} else {
			$(this).parents('tr').next().hide();
		}
	 });
	 $('#role').change(); */
	 $('#role').change(function() {
		 	if ($(this).val() == "{$role_merch}") {
				$(this).parents('tr').next().show();
			} else {
				$(this).parents('tr').next().hide();
			}
		 });
	 $('#role').change();
	 $('#source').children().each(function(i) {
	 	var _this = $(this);
	 	$('#target').children().each(function(j) {
			if ($(this).val() == _this.val()) {
				$(this).attr('num', _this.attr('num'));
				_this.remove();
			}
		});
	 });
	 $('input.btn-1').click(function() {
	 	if ($(this).val() == '>>') {
			$('#source').children().appendTo($('#target'));
			sort_merchandiser('target');
		} else if ($(this).val() == '>') {
			var source = $('#source option:selected');
			source.appendTo($('#target'));
			sort_merchandiser('target');
		} else if ($(this).val() == '<') {
			var target = $('#target option:selected');
			target.appendTo($('#source'));
			sort_merchandiser('source');
		} else {
			$('#target').children().appendTo($('#source'));
			sort_merchandiser('source');
		}
	 });
	 $('#source').dblclick(function() {
	 	$('#source option:selected').appendTo($('#target'));
		sort_merchandiser('target');
	 });
	 $('#target').dblclick(function() {
	 	$('#target option:selected').appendTo($('#source'));
		sort_merchandiser('source');
	 });
	 
	 $("select.chzn-select").chosen();

});
function sort_merchandiser(id)
{
	var obj = $('#' + id);
	obj.children().each(function(i) {
		var _this = $(this);
		obj.children().each(function(j) {
			if (Number($(this).attr('num')) < Number(_this.attr('num'))) {
				$(this).insertBefore(_this);
			}
		});
	});
	merchandiser_ids();
}
function merchandiser_ids()
{
	var ids = '';
	$('#target').children().each(function(i) {
		ids += $(this).val() + ',';
	});
	ids = ids.substr(0, ids.length - 1);
	$('#merchandiser').val(ids);
}
</script>
<body>
<style>
label.error {margin-left:2em; color:#FF0000;}
.tab-frame{width:900px;}
input {
	vertical-align: -5px;_vertical-align: -1px;margin-right: 5px
}
</style>
<div class="sub-body">
<div class="tab-frame">
<div class="tab-title-1">
<!--{if $smarty.get.act eq 'add'}-->
{if $smarty.get.addtype eq 'factory'}
<span>添加工厂用户</span>
{else}
<span>{$lang.add_new_user}</span>
{/if}
<!--{else}--><span>{$lang.edit_user}</span><!--{/if}-->
</div>
<form action="{url app=member&act=$smarty.get.act}{if $smarty.get.uid}&amp;uid={$smarty.get.uid}{/if}{if $smarty.get.act eq 'add' AND $smarty.get.addtype eq 'factory'}&addtype=factory{/if}" method="post" id="user_form">
<table width="100%" cellspacing="0" cellpadding="0" class="tab-display">
	<tr>
		<th width="100" align="right">{$lang.user_name}：</th>
		<td align="left">
        {if $smarty.get.act eq 'add'}
        {if $smarty.get.addtype eq 'factory'}
        <select name="factory_id" data-placeholder="请选择" class="chzn-select">
        <option value="0">{$lang.select_pls}</option>
        <!--{foreach from=$factory_list item=factory}-->
        <option value="{$factory.factory_id}">{$factory.factory_name}</option>
       <!-- {/foreach}-->
       </select>
        {else}<input type="text"  name="user_name" id="user_name" value="{$user.user_name}" class="input-1" />{/if}
        {else}
        	<input type="text"  {if $user.is_factory eq 1}disabled{/if} name="user_name" id="user_name" value="{$user.user_name}" class="input-1" />
        {/if}
        </td>
	</tr>
	<tr>
		<th align="right">{$lang.ch_name}：</th>
		<td align="left"><input type="text" name="ch_name" class="input-1" value="{$user.ch_name}" /></td>
	</tr>
	<tr>
		<th align="right">{$lang.password}：</th>
		<td align="left"><input type="password" name="password" id="password" class="input-1" /><input type="hidden" name="old_pwd" value="{$user.password}" class="input-1"/></td>
	</tr>
	<tr>
		<th align="right">{$lang.confirm_password}：</th>
		<td align="left"><input type="password" name="password2" class="input-1" /></td>
	</tr>
    <tr>
		<th align="right">{$lang.email}：</th>
		<td align="left"><input type="email" name="email" class="input-1" value="{$user.email}" /></td>
	</tr>
	<tr>
		<th align="right">{$lang.address}：</th>
		<td align="left"><input type="text" name="address" class="input-1" value="{$user.address}" style="width: 500px;"/></td>
	</tr>
	<tr>
		<th align="right">{$lang.phone_mob}：</th>
		<td align="left"><input type="text" name="phone_mob" class="input-1" value="{$user.phone_mob}" /></td>
	</tr>
	<tr>
		<th align="right">{$lang.phone_tel}：</th>
		<td align="left"><input type="text" name="phone_tel" class="input-1" value="{$user.phone_tel}" /></td>
	</tr>
	<tr>
		<th align="right">{$lang.im_qq}：</th>
		<td align="left"><input type="text" name="im_qq" class="input-1" value="{$user.is_qq}" /></td>
	</tr>
	<tr>
		<th align="right">{$lang.role}：</th>
		<td align="left">
			<select name="role" id="role">
        
        {if $smarty.get.addtype eq 'factory'||$user.is_factory eq 1}
			<!--{foreach from=$lang.roles item=role key=k}-->
            	{if $k eq USER_FACTORY}
				<option value="{$k}" {if $user.role == $k}selected="selected"{/if}>{$role}</option>
                {/if}
				<!--{/foreach}-->
        {else}
			<option value="">{$lang.select_pls}</option>
				<!--{foreach from=$lang.roles item=role key=k}-->
                {if $k neq USER_FACTORY && $k neq USER_CLIENT && $k neq USER_MERCHANT}
				<option value="{$k}" {if $user.role == $k}selected="selected"{/if}>{$role}</option>
                {/if}
				<!--{/foreach}-->
        {/if}
				
			</select>
		</td>
	</tr>
	<tr style="display:none;" id="role_cate">
		<th align="right">{$lang.special_function}：</th>
		<td align="left"><input type="checkbox" name="role_cate" class="input-1" value="2" {if $user.role_cate==ROLE_MERCH}checked{/if}/>{$lang.assign_sample}&nbsp;&nbsp;<input type="checkbox" name="default_merch" class="input-1" value="1" {if $user.default_merch==USER_DEFAULT_ORDER}checked{/if}/>{$lang.setting_default_merch}</td>
	</tr> 
	<!-- <tr style="display:none;">
		<th align="right">{$lang.merchandiser}：</th>
		<td align="left">
			<select size="10" style="float:left; width:120px; height:143px;" id="source">
				{foreach from=$merchandiser_list item=merchandiser name=n}
				<option value="{$merchandiser.user_id}" num="{$smarty.foreach.n.iteration}">{$merchandiser.user_name|escape}</option>
				{/foreach}
			</select>
			<span style="float:left; padding:20px 10px 0 10px;">
			<input type="button" class="btn-1" value=">>" style="margin-top:3px;" /><br>
			<input type="button" class="btn-1" value=">" style="margin-top:3px;" /><br>
			<input type="button" class="btn-1" value="<" style="margin-top:3px;" /><br>
			<input type="button" class="btn-1" value="<<" style="margin-top:3px;" />
			</span>
			<select size="10" style="float:left; width:120px; height:143px;" id="target">
				{foreach from=$merchandiser_list1 item=merchandiser name=n}
				<option value="{$merchandiser.user_id}" num="{$smarty.foreach.n.iteration}">{$merchandiser.user_name|escape}</option>
				{/foreach}
			</select>
			<input type="hidden" name="merchandiser" id="merchandiser" value="" />
		</td>
	</tr> -->
	<tr>
		<th align="right">{$lang.is_activation}：</th>
		<td align="left"><label><input type="radio" name="activation" value="1" {if $user.activation == 1}checked="checked"{/if} />{$lang.yes}</label>&nbsp;&nbsp;&nbsp;&nbsp;<label><input type="radio" name="activation" value="0" {if !$user.if_show}checked="checked"{/if} />{$lang.no}</label></td>
	</tr>
	<tr>
		<th align="right">{$lang.member_img_upload}：</th>
		<td align="left">
			<input type="button" class="btn-3" value="{$lang.member_img_upload}" onClick="upload_docs({$belongs_member_img}, {$user.user_id|default:$default_cust_id});" />
			<div id="member_beautiful_img">
                <!--{foreach from=$user.member_img item=file}-->
                <span><a href="download.php?id={$file.file_id}" ><img src="{$file.file_path}" title="{$file.file_name}" width="100px" height="120px"></img></a>
                <a class="pic_del" href="{url app=comupload&act=delete&id=$file.file_id}" onClick="return confirm('{$lang.confirm_del_file}')" title="{$lang.delete}">&nbsp;</a>
                </span>
				<!--{if !$smarty.foreach.last}--><!--{/if}--><!--{/foreach}-->
            </div>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center"><input type="submit" value="{$lang.submit}" class="btn-2" /></td>
	</tr>
</table>
</form>
<script language="javascript" type="text/javascript" src="{res file=js/tab_color.js}"></script>
</div>
</div>
</body>
</html>